﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>字段权限</title>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>

    <base target="_self" />
    <style type="text/css">
        th, td {
            text-align: center;
        }

        input[type=checkbox], input[type=radio] {
            margin-top: 0px;
        }
    </style>
    <script type="text/javascript">
        var frmID;
        var fk_flow;
        var fk_Node;
        var isShowNDRpt = false;
        $(function () {

            var frmID = GetQueryString("FK_MapData");
            var nodeID = GetQueryString("FK_Node");
            var flowNo = GetQueryString("FK_Flow");

            //判断节点表单类型,如果是树节点，就显示写入NDxxRpt列.
            var isShowNDRpt = false;
            var node = new Entity("BP.WF.Node", nodeID);
            if (node.FormType == 5 || node.FormType == 11)
                isShowNDRpt = true;

            if (isShowNDRpt == false) {
                $("#HDRpt").hide();
            }

            //获得字段集合.
            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", frmID, "Y");
            fieldsData = mapAttrs;

            var groups = new Entities("BP.Sys.GroupFields", "FrmID", frmID);
            for (var k = 0; k < groups.length; k++) {
                var group = groups[k];
                if (group.CtrlType == "Ath" || group.CtrlType == "Dtl")
                    continue;

                html = "";
                html += "<tr>";
                html += "<td colspan=12 class=Sum><b>" + group.Lab + "</b></td>";
                html += "</tr>";
                $("#Table1 tr:last").after(html);

                for (var i = 0; i < mapAttrs.length; i++) {
                    var en = mapAttrs[i];
                    if (en.EditType != 0  || en.KeyOfEn == "FID")
                        continue;

                    var html = "";
                    html += "<tr >";
                    html += "<td class=Idx>" + (i + 1) + "</td>";
                    html += "<td>" + en.KeyOfEn + "</td>";
                    html += "<td>" + en.Name + "</td>";

                    if (en.UIContralType >= 4) {
                        html += "<td class=Sum>组件</td>";
                    } else {
                        if (en.LGType == 0) html += "<td>普通</td>";
                        if (en.LGType == 1) html += "<td>枚举</td>";
                        if (en.LGType == 2) html += "<td>外键</td>";
                    }
                    if (en.UIContralType >= 4) {
                        html += "<td colspan=2> - </td>";
                    } else {
                        html += "<td><input onkeydown='upischange(" + i + ");' id='" + en.KeyOfEn + "_RegularExp" + "' type='text' placeholder='正则表达式' value=''/></td>";
                        html += "<td><input onkeydown='upischange(" + i + ");' id='" + en.KeyOfEn + "_DefVal" + "' type='text' placeholder='默认值…' value='" + en.DefVal + "'/>&nbsp;&nbsp;<a href='#' onclick=ShowHidden('state','" + en.KeyOfEn + "')>默认值<a/></td>";
                    }
                    html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='UIVisible' id='" + en.KeyOfEn + "_UIVisible" + "' type='checkbox' " + (en.UIVisible ? "checked" : "") + "><div id='lab_" + en.KeyOfEn + "_UIVisible" + "' style='padding-left:20px;'>可见</div></label></td>";
                    if (en.UIContralType == 14) {
                        html += "<td> - </td>";
                    } else {

                        html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='UIIsEnable' id='" + en.KeyOfEn + "_UIIsEnable" + "' type='checkbox' " + (en.UIIsEnable ? "checked" : "") + "><div id='lab_" + en.KeyOfEn + "_UIIsEnable" + "'style='padding-left:30px;'>可编辑</div></label></td>";
                    }
                    if (en.UIContralType >= 4) {
                        html += "<td colspan=3> - </td>";
                    } else {
                        html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='IsSigan' id='" + en.KeyOfEn + "_IsSigan" + "' type='checkbox' " + (en.IsSigan ? "checked" : "") + "><div id='lab_" + en.KeyOfEn + "_IsSigan" + "'style='padding-left:20px;'>签名</div></label></td>";
                        html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='IsNotNull' id='" + en.KeyOfEn + "_IsNotNull" + "' type='checkbox' " + (en.UIIsInput ? "checked" : "") + "><div id='lab_" + en.KeyOfEn + "_IsNotNull" + "'style='padding-left:20px;'>必填</div></label></td>";
                        if (isShowNDRpt == true)
                            html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='IsWriteToFlowTable' id='" + en.KeyOfEn + "_IsWriteToFlowTable" + "' type='checkbox' " + (en.IsWriteToFlowTable ? "checked" : "") + " style='margin-left:-45px'><div id='lab_" + en.KeyOfEn + "_IsWriteToFlowTable" + "'style='padding-left:20px;'>写入ND" + parseInt(flowNo) + "Rpt</div></label></td>";

                    }
                    //html += "<td><label class='checkbox' ><input onclick='checkclick(this," + i + ");' class='IsWriteToGenerWorkFlow' id='" + en.KeyOfEn + "_IsWriteToGenerWorkFlow" + "' type='checkbox' " + (en.IsWriteToGenerWorkFlow ? "checked" : "") + "><div id='lab_" + en.KeyOfEn + "_IsWriteToGenerWorkFlow" + "'>写入WF_GernrWorkFlow</div></label></td>";
                    html += "</tr>";

                    $("#Table1 tr:last").after(html);
                }
            }

            //获得FF集合，个性化的设置信息都在这个表里面与Sys_MapAttr无关系.
            var ffs = new Entities("BP.WF.Template.FrmFields");
            ffs.Retrieve("FK_MapData", frmID, "FK_Node", nodeID);


            //给相关的字段赋值.
            for (var i = 0; i < ffs.length; i++) {

                var ff = ffs[i];

                $("#" + ff.KeyOfEn + "_DefVal").val(ff.DefVal); //设置默认值.
                $("#" + ff.KeyOfEn + "_RegularExp").val(ff.RegularExp); //设置默认值.

                SetCheckBox(ff, "UIVisible", ff.UIVisible, '可见');
                SetCheckBox(ff, "UIIsEnable", ff.UIIsEnable, '可编辑');
                SetCheckBox(ff, "IsSigan", ff.IsSigan, '签名');
                SetCheckBox(ff, "IsNotNull", ff.IsNotNull, '必填');
                SetCheckBox(ff, "IsWriteToFlowTable", ff.IsWriteToFlowTable, '写入NDxxRpt');
                SetCheckBox(ff, "IsWriteToGenerWorkFlow", ff.IsWriteToGenerWorkFlow, '写入WF_GernrWorkFlow');
            }

            //绑定节点: 为海事局处理.
            var ffs = new Entities("BP.WF.Template.FrmNodes");
            ffs.Retrieve("FK_Frm", frmID, "FK_Flow", node.FK_Flow);

            var html = "<table>";
            //    html += "<caption>请选择节点</caption>";
            html += "<tr>";
            html += "<td>请选择节点:</td>";
            for (var i = 0; i < ffs.length; i++) {
                var en = ffs[i];
                var mynd = new Entity("BP.WF.Node", en.FK_Node);
                if (en.FK_Node == node.NodeID)
                    html += "<td><b>" + mynd.Name + "</b></td>";
                else
                    html += "<td><a href='?FK_MapData=" + frmID + "&FK_Node=" + mynd.NodeID + "' >" + mynd.Name + "</a></td>";
            }
            html += "</tr>";
            html += "</table>";

            $("#NDs").html(html);

        });
        function AddDefVal(no, id) {
            document.getElementById(id + "_DefVal").value = no;
        }
        /*隐藏与显示.*/
        function ShowHidden(ctrlID, inputID) {
            var ens = new Entities("BP.Sys.GloVars");
            ens.Retrieve("GroupKey", "DefVal");

            //var sql = "SELECT No,Name FROM Sys_GloVar WHERE GroupKey='DefVal'";
            //var dts = DBAccess.RunSQLReturnTable(sql);
            html = "<div id='state' style='padding-top:20px; padding-left:60px; width:360px; height:400px; position: absolute; z-index: 10; background-color: #F5F5F5; border: 2px outset black; display: none; color: Gray; top:100px;left:500px;>";
            html += "<h4>系统默认值</h4>";
            html += " <ol style='padding:10px;'>";
            for (var i = 0; i < ens.length; i++) {
                var en = ens[i];
                html += " <li><a href=\"javascript:AddDefVal('" + en.No + "','" + inputID + "')\"> " + en.Name + " </a> </li>";
            }
            html += " </ol>";
            html += "</div>";

            $("#Table1").after(html);

            var ctrl = document.getElementById(ctrlID);

            ctrl.style.display = 'block';

            document.onmouseup = function () {

                ctrl.style.display = "none";
            }
        }
        function SetCheckBox(ff, key, val, label) {

            //是否可用.
            var isCheckedReal = $('#' + ff.KeyOfEn + "_" + key).is(':checked');
            if (isCheckedReal == true)
                isCheckedReal = 1;
            else
                isCheckedReal = 0;

            if (val != isCheckedReal) {
                if (val == 1)
                    $("#" + ff.KeyOfEn + "_" + key).attr("checked", true);
                else
                    $("#" + ff.KeyOfEn + "_" + key).attr("checked", false);

                $("#lab_" + ff.KeyOfEn + "_" + key).html("<font color=green><b>" + label + "</b></font>");
            }
        }

        var FieldsAttrs = new Object();
        var fieldsData = null;

        //保存字段方案
        function Save() {

            $("#Btn_Save").text("正在保存..");

            var frmID = GetQueryString("FK_MapData");
            var nodeID = parseInt(GetQueryString("FK_Node"));
            var flowNo = GetQueryString("FK_Flow");

            //获得字段集合.
            var mapAttrs = new Entities("BP.Sys.MapAttrs");
            mapAttrs.Retrieve("FK_MapData", frmID);

            //删除以前的设置..
            var ff = new Entity("BP.WF.Template.FrmField");
            ff.Delete("FK_MapData", frmID, "FK_Node", nodeID);

            for (var i = 0; i < mapAttrs.length; i++) {
                var en = mapAttrs[i];
                if (en.EditType != 0 || en.KeyOfEn == "FID")
                    continue;

                ff = new Entity("BP.WF.Template.FrmField");
                ff.SetPKVal(frmID + '_' + nodeID + '_' + en.KeyOfEn);

                ff.FK_Flow = flowNo;
                ff.FK_Node = nodeID;
                ff.FK_MapData = frmID;
                ff.KeyOfEn = en.KeyOfEn;
                ff.EleType = "Field";
                ff.Name = en.Name;

                //给其他的字段赋值.
                ff.DefVal = $("#" + en.KeyOfEn + "_DefVal").val(); //默认值.
                ff.RegularExp = $("#" + en.KeyOfEn + "_RegularExp").val(); //表达式.

                if ($('#' + ff.KeyOfEn + "_UIVisible").is(':checked'))
                    ff.UIVisible = 1;
                else
                    ff.UIVisible = 0;

                if ($('#' + ff.KeyOfEn + "_UIIsEnable").is(':checked'))
                    ff.UIIsEnable = 1;
                else
                    ff.UIIsEnable = 0;

                if ($('#' + ff.KeyOfEn + "_IsSigan").is(':checked'))
                    ff.IsSigan = 1;
                else
                    ff.IsSigan = 0;

                if ($('#' + ff.KeyOfEn + "_IsNotNull").is(':checked'))
                    ff.IsNotNull = 1;
                else
                    ff.IsNotNull = 0;

                if ($('#' + ff.KeyOfEn + "_IsWriteToFlowTable").is(':checked'))
                    ff.IsWriteToFlowTable = 1;
                else
                    ff.IsWriteToFlowTable = 0;

                //if ($('#' + ff.KeyOfEn + "_IsWriteToGenerWorkFlow").is(':checked'))
                //    ff.IsWriteToGenerWorkFlow = 1;
                //else
                //    ff.IsWriteToGenerWorkFlow = 0;

                //判断变化的是否需要保存.
                var isNeedSave = false;
                //if (ff.IsWriteToGenerWorkFlow == 1)
                //    isNeedSave = true;

                if (ff.IsWriteToFlowTable == 1)
                    isNeedSave = true;

                if (en.UIVisible != ff.UIVisible)
                    isNeedSave = true;

                if (en.UIIsEnable != ff.UIIsEnable)
                    isNeedSave = true;

                if (en.DefVal != ff.DefVal)
                    isNeedSave = true;

                if (en.UIIsInput != ff.IsNotNull)
                    isNeedSave = true;

                if (ff.RegularExp != "")
                    isNeedSave = true;

                if (isNeedSave == false)
                    continue;

                ff.Insert();
            }
            $("#Btn_Save").text(" 保 存 ");

            Reload();
        }

        function replaceTrim(val) {//去除空格
            return val.replace(/[ ]/g, "");
        }

        function upischange(index) {
            fieldsData[index].IsChange = true;
        }
        //绑定是否全选或者取消全选
        function checkclick(o, index) {
            upischange(index);
            var ischeckedall = true;
            var rowstype = o.classList;
            $('.' + rowstype).each(function () {
                if (this.type == 'checkbox' && !this.checked) {
                    ischeckedall = false;
                    return ischeckedall;
                }
            });

            if (ischeckedall)
                $('#KeyOfEn_' + rowstype)[0].checked = true;
            else
                $('#KeyOfEn_' + rowstype)[0].checked = false;
        }

        //全选或者反选
        function CheckAll(rowstype) {

            $('.' + rowstype).each(function () {
                if (this.type == 'checkbox') {
                    $('#KeyOfEn_' + rowstype)[0].checked ? this.checked = true : this.checked = false;
                }
            });

            upstate(true);
        }

        function upstate(ischange) {
            for (var i = 0; i < fieldsData.length; i++) {
                en.IsChange = ischange;
            }
        }

        /**/</script>
</head>
<body>
    <div class="container-full">
        <div class="attrnode-bar-header">
            <span class="pull-right">

                <button id="Btn_Save" name="Btn_Save" onclick="Save();" class="cc-btn-tab btn-save">保存</button>

            </span>
            <strong> 节点-表单-字段权限</strong>
        </div>
        <table id="Table1" class="table">
            <caption>
                <div id="NDs"></div>
            </caption>
            <tr>
                <th width="60">
                    序
                </th>
                <th>
                    字段
                </th>
                <th>
                    名称
                </th>
                <th>
                    类型
                </th>
                <th>
                    正则表达式
                </th>
                <th>
                    默认值
                </th>
                <th>
                    <label for="KeyOfEn_UIVisible">
                        <input onclick="CheckAll('UIVisible');" id='KeyOfEn_UIVisible' type="checkbox" />
                        可见
                    </label>
                </th>
                <th>
                    <label for="KeyOfEn_UIIsEnable">
                        <input onclick="CheckAll('UIIsEnable');" id='KeyOfEn_UIIsEnable' type='checkbox' />
                        可编辑
                    </label>
                </th>
                <th>
                    <label for="KeyOfEn_IsSigan">
                        <input onclick="CheckAll('IsSigan');" id='KeyOfEn_IsSigan' type='checkbox' />
                        签名
                    </label>
                </th>
                <th>
                    <label for="KeyOfEn_IsNotNull">
                        <input onclick="CheckAll('IsNotNull');" id='KeyOfEn_IsNotNull' type='checkbox' />
                        必填
                    </label>
                </th>
                <th id="HDRpt">
                    <input onclick="CheckAll('IsWriteToFlowTable');" id='KeyOfEn_IsWriteToFlowTable'
                           type='checkbox' /><label for="KeyOfEn_IsWriteToFlowTable">
                        其他
                    </label>
                </th>
                <!--<th>
                    <input onclick="CheckAll('IsWriteToGenerWorkFlow');" id='KeyOfEn_IsWriteToGenerWorkFlow'
                        type='checkbox' /><label for="KeyOfEn_IsWriteToGenerWorkFlow">
                            写入流程注册表
                        </label>
                </th>-->
            </tr>
        </table>


    </div>

</body>
</html>
